package auth2x

import (
	"golang.org/x/oauth2"
	"net/url"
)

const (
	ClientID     = "8990ca6b3fdadb6463fbf9ec80f6302e782d60d66e6552eb7a99824c3d0e76f3"
	ClientSecret = "a33ea17a5529a7f57854d6ee56d36bc7bf1c0c6180a542ee2d11d10584c9d1db"
)

var (
	GiteeOauth, _ = url.Parse("https://gitee.com/oauth/authorize")
	GiteeToken, _ = url.Parse("https://gitee.com/oauth/token")
)

var Refresh = func(refresh_token string) string {
	values := url.Values{}
	values.Set("grant_type", "refresh_token")
	values.Set("refresh_token", "refresh_token")
	return values.Encode()

}

func GiteeAuthUrl(config oauth2.Config) string {
	query, err := url.ParseQuery("client_id={client_id}&redirect_uri={redirect_uri}&response_type=code")
	if err != nil {
		return ""
	}
	query.Set("client_id", config.ClientID)
	query.Set("redirect_uri", config.RedirectURL)
	query.Set("response_type", "code")
	GiteeOauth.RawQuery = query.Encode()

	return GiteeOauth.String()
}

var GiteeScope = []string{
	"user_info", "projects", "pull_requests", "issues", "notes", "keys", "hook", "groups", "gists", "enterprises",
}
